﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;
namespace Giao_dien_2.FormCT
{
    public partial class FormDoiMatKhau : DevExpress.XtraEditors.XtraForm
    {
        public FormDoiMatKhau()
        {
            InitializeComponent();
        }
        public string manguoidung="";
        DBGiaoNhan giaonhan = new DBGiaoNhan();
        public bool kiemtra(string mk)
        {

            if (txt_mkcu.Text != mk)
            { 
                MessageBox.Show("Sai mật khẩu cũ", "Thông báo"); 
                clean();
                return false; 
            }
                    else if (txt_mkmoi.Text != txt_nhaplaimkmoi.Text)
                    {
                        MessageBox.Show("Mật Khẩu nhập lại sai", "Thông báo"); 
                        clean();
                        return false;
                    }
                        else return true;                         
        }
        public void clean()
        {
            txt_mkcu.Text = "";
            txt_mkmoi.Text = "";
            txt_nhaplaimkmoi.Text = "";
            txt_mkcu.Focus();
        }
        private void btn_dongy_Click(object sender, EventArgs e)
        {
            try
            {
                NHANVIENHC nvhc = giaonhan.NHANVIENHCs.Single(p => p.MaNVHC == manguoidung);
                if (kiemtra(nvhc.MatKhau))
                {
                    nvhc.MatKhau = txt_mkmoi.Text;
                    giaonhan.SubmitChanges();
                    MessageBox.Show("Đổi mật khẩu thành công", "Thông Báo");
                    foreach (Giaodien f in Application.OpenForms)
                    {
                        f.Enabled = true;
                        f.Focus();
                        this.Close();
                        return;
                    }
                    
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btb_huy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

   }
}